<?php
defined('IN_MAIN') or exit('Invalid Access!');

function generate_code(){	$code = rand() % 999999;	
	$exist = true;	while($code<100000 || $exist==true){		$rs = mysql_query("select id from gg_users where code=".$code);				if($rs){			if(mysql_num_rows($rs)>0){								$code = rand() % 999999;								$exist = true;				}else{								$exist = false;							}					}else{						$exist = false;					}			}	
	return $code;
}

function create_matrix($new_uid){
	global $vars;
 	$db=$vars["db"];
	
	$sql="INSERT INTO $db->matrix_first (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
					
	$sql="INSERT INTO $db->matrix_second (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
					
	$sql="INSERT INTO $db->matrix_third (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
					
	$sql="INSERT INTO $db->matrix_fourth (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
					
	$sql="INSERT INTO $db->matrix_fifth (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
					
	$sql="INSERT INTO $db->matrix_sixth (uid) VALUES (".$new_uid.")";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";

	$sql="update gg_settings set value='".$sql."' where param='maintenance'";
	if(!mysql_query($sql))
		$errmsg.=__("We have encountered some error and the registration process has been failed.")."<br />\nError: ".mysql_error()."<br />\n";
}


function auto_matrix1($sponsor_id){
	global $vars;
 	$db=$vars["db"];
 	
	$sql = "SELECT id, ref, total_sponsor_1 FROM $db->users WHERE id=".$sponsor_id;
	$user_account=@mysql_fetch_assoc(mysql_query($sql));
	if($user_account['total_sponsor_1']=='2'){
		$sql = "SELECT id, lvl_1 FROM $db->matrix_first WHERE uid=".$user_account['id'];
		$user_matrix=@mysql_fetch_assoc(mysql_query($sql));
		if($user_matrix['lvl_1']=='0'){
			//own point
			$sql = "UPDATE $db->matrix_first SET lvl_1=".$user_account['id'].",date_1='".date('Y-m-d')."' WHERE id=".$user_matrix['id'];
			mysql_query($sql);
							
			//first point
			$sql = "SELECT * FROM $db->matrix_first WHERE uid=".$user_account['ref'];
			$sponsor_matrix=@mysql_fetch_assoc(mysql_query($sql));
			if($sponsor_matrix['lvl1_1']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl1_1=".$user_account['id'].",date1_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_2']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl1_2=".$user_account['id'].",date1_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_3']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl1_3=".$user_account['id'].",date1_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_1']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_1=".$user_account['id'].",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_2']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_2=".$user_account['id'].",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_3']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_3=".$user_account['id'].",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_4']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_4=".$user_account['id'].",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_5']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_5=".$user_account['id'].",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_6']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_6=".$user_account['id'].",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_7']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_7=".$user_account['id'].",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_8']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_8=".$user_account['id'].",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_9']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_9=".$user_account['id'].",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
		}
						
		//second point
		$sql = "SELECT * FROM $db->matrix_first WHERE lvl1_1=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_1']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_1=".$user_account['id'].",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_2']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_2=".$user_account['id'].",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_3']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_3=".$user_account['id'].",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
		}
		//second point
		$sql = "SELECT * FROM $db->matrix_first WHERE lvl1_2=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_4']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_4=".$user_account['id'].",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_5']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_5=".$user_account['id'].",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_6']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_6=".$user_account['id'].",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
		}
		//second point
		$sql = "SELECT * FROM $db->matrix_first WHERE lvl1_3=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_7']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_7=".$user_account['id'].",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_8']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_8=".$user_account['id'].",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_9']=='0'){
				$sql = "UPDATE $db->matrix_first SET lvl2_9=".$user_account['id'].",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
		}
		mysql_query($sql);
	}
}

function auto_matrix4($sponsor_id){
	global $vars;
 	$db=$vars["db"];
 	
 	$sql = "SELECT id, ref, total_sponsor_2 FROM $db->users WHERE id=".$sponsor_id;
	$user_account=@mysql_fetch_assoc(mysql_query($sql));
	if($user_account['total_sponsor_2']=='2'){
		$sql = "SELECT id, lvl_1 FROM $db->matrix_fourth WHERE uid=".$user_account['id'];
		$user_matrix=@mysql_fetch_assoc(mysql_query($sql));
		if($user_matrix['lvl_1']=='0'){
			//own point
			$sql = "UPDATE $db->matrix_fourth SET lvl_1=".$user_account['id'].",date_1='".date('Y-m-d')."' WHERE id=".$user_matrix['id'];
			mysql_query($sql);
			
			//first point
			$sql = "SELECT * FROM $db->matrix_fourth WHERE uid=".$user_account['ref'];
			$sponsor_matrix=@mysql_fetch_assoc(mysql_query($sql));
			if($sponsor_matrix['lvl1_1']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl1_1=".$user_account['id'].",date1_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_2']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl1_2=".$user_account['id'].",date1_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_3']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl1_3=".$user_account['id'].",date1_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_1']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_1=".$user_account['id'].",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_2']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_2=".$user_account['id'].",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_3']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_3=".$user_account['id'].",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_4']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_4=".$user_account['id'].",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_5']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_5=".$user_account['id'].",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_6']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_6=".$user_account['id'].",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_7']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_7=".$user_account['id'].",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_8']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_8=".$user_account['id'].",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_9']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_9=".$user_account['id'].",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
		}
		
		//second point
		$sql = "SELECT * FROM $db->matrix_fourth WHERE lvl1_1=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_1']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_1=".$user_account['id'].",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_2']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_2=".$user_account['id'].",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_3']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_3=".$user_account['id'].",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
		}
		//second point
		$sql = "SELECT * FROM $db->matrix_fourth WHERE lvl1_2=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_4']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_4=".$user_account['id'].",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_5']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_5=".$user_account['id'].",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_6']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_6=".$user_account['id'].",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
		}
		//second point
		$sql = "SELECT * FROM $db->matrix_fourth WHERE lvl1_3=".$user_account['ref'];
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			$sponsor_matrix=@mysql_fetch_assoc($q);
			if($sponsor_matrix['lvl2_7']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_7=".$user_account['id'].",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_8']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_8=".$user_account['id'].",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl2_9']=='0'){
				$sql = "UPDATE $db->matrix_fourth SET lvl2_9=".$user_account['id'].",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
		}
				
		//check full matrix
		//$sql = "SELECT uid FROM $db->matrix_fourth WHERE lvl_1>0 AND lvl1_1>0 AND lvl1_2>0 AND lvl2_1>0 AND lvl2_2>0 AND lvl2_4>0 AND lvl2_5>0 AND is_qualify=0";
		$sql = "SELECT uid FROM $db->matrix_fourth WHERE lvl_1>0 AND lvl1_1>0 AND lvl1_2>0 AND ((lvl2_1>0 AND lvl2_2>0 AND lvl2_4>0 AND lvl2_5>0) OR (lvl2_4>0 AND lvl2_5>0 AND lvl2_7>0 AND lvl2_8>0) OR (lvl2_1>0 AND lvl2_2>0 AND lvl2_7>0 AND lvl2_8>0)) AND is_qualify=0";
		$q = mysql_query($sql);							
		if(mysql_num_rows($q)>0){
			while ($complete_matrix = mysql_fetch_assoc($q)) {
				auto_matrix5($complete_matrix["uid"]);				
			}
		}
	}
}

function auto_matrix5($user_id=0){	
	global $vars;
 	$db=$vars["db"];
 	
	if($user_id>0){
		$atree=array();
		array_push($atree,'1');
		
		while(sizeof($atree)) {
	
			$node=array_shift($atree);
		 	$nd=0;
			$np=1;
	
			$strsq1="select id,fifth_position from $db->users where fifth_upline=".$node." order by fifth_position";
			$rs = mysql_query($strsq1);	
	
			while ($member = mysql_fetch_assoc($rs)) {	
				array_push($atree,$member["id"]);
				$nd++;
				
				if($np==$member["fifth_position"] or $member["fifth_position"]==0) $np++;
			}

			if($np<=3 && $node<>'0') break;		
		}

		if($np<=3 && $node<>'0') {
			$sql = "UPDATE $db->users SET fifth_upline=".$node.",fifth_position=".$np.",fifth_date='".date('Y-m-d')."' WHERE id=".$user_id;
			mysql_query($sql);
			
			//own point
			$sql = "UPDATE $db->matrix_fifth SET lvl_1=".$user_id.",date_1='".date('Y-m-d')."' WHERE uid=".$user_id;
			mysql_query($sql);
			$sql = "UPDATE $db->matrix_fourth SET is_qualify=1 WHERE uid=".$user_id;				
			mysql_query($sql);
			
			//first point
			$sql = "SELECT * FROM $db->matrix_fifth WHERE uid=".$node;
			$sponsor_matrix=@mysql_fetch_assoc(mysql_query($sql));
			if($sponsor_matrix['lvl1_1']=='0' && $np=='1'){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_1=".$user_id.",date1_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_2']=='0' && $np=='2'){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_2=".$user_id.",date1_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_3']=='0' && $np=='3'){
				$sql = "UPDATE $db->matrix_fifth SET lvl1_3=".$user_id.",date1_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
			
			//second point
			$sql = "SELECT * FROM $db->matrix_fifth WHERE lvl1_1=".$node;
			$q = mysql_query($sql);							
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_1']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_1=".$user_id.",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_2']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_2=".$user_id.",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_3']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_3=".$user_id.",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}
			//second point
			$sql = "SELECT * FROM $db->matrix_fifth WHERE lvl1_2=".$node;
			$q = mysql_query($sql);							
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_4']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_4=".$user_id.",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_5']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_5=".$user_id.",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_6']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_6=".$user_id.",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}
			//second point
			$sql = "SELECT * FROM $db->matrix_fifth WHERE lvl1_3=".$node;
			$q = mysql_query($sql);
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_7']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_7=".$user_id.",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_8']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_8=".$user_id.",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_9']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_fifth SET lvl2_9=".$user_id.",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}
		}

		//check full matrix
		$sql = "SELECT uid FROM $db->matrix_fifth WHERE lvl_1>0 AND lvl1_1>0 AND lvl1_2>0 AND lvl1_3>0 AND lvl2_1>0 AND lvl2_2>0 AND lvl2_3>0 AND lvl2_4>0 AND lvl2_5>0 AND lvl2_6>0 AND lvl2_7>0 AND lvl2_8>0 AND lvl2_9>0 AND is_qualify=0";
		$q = mysql_query($sql);
		$sql2 = "SELECT uid FROM $db->matrix_fourth WHERE lvl_1>0 AND lvl1_1>0 AND lvl1_2>0 AND lvl1_3>0 AND lvl2_1>0 AND lvl2_2>0 AND lvl2_3>0 AND lvl2_4>0 AND lvl2_5>0 AND lvl2_6>0 AND lvl2_7>0 AND lvl2_8>0 AND lvl2_9>0 AND is_qualify=1";
		$q2 = mysql_query($sql2);							
		if(mysql_num_rows($q)>0 && mysql_num_rows($q2)>0){
			while ($complete_matrix = mysql_fetch_assoc($q)) {
				auto_matrix6($complete_matrix["uid"]);
				mysql_query("UPDATE $db->matrix_fifth SET is_qualify=1 WHERE uid=".$complete_matrix["uid"]);
			}
		}
	}
}

function auto_matrix6($user_id=0){	
	global $vars;
 	$db=$vars["db"];
 	
	if($user_id>0){
		$atree=array();
		array_push($atree,'44');
		
		while(sizeof($atree)) {
	
			$node=array_shift($atree);
		 	$nd=0;
			$np=1;
	
			$strsq1="select id,sixth_position from $db->users where sixth_upline=".$node." order by sixth_position";
			$rs = mysql_query($strsq1);	
	
			while ($member = mysql_fetch_assoc($rs)) {	
				array_push($atree,$member["id"]);
				$nd++;
				
				if($np==$member["sixth_position"] or $member["sixth_position"]==0) $np++;
			}

			if($np<=3 && $node<>'0') break;		
		}

		if($np<=3 && $node<>'0') {
			$sql = "UPDATE $db->users SET sixth_upline=".$node.",sixth_position=".$np.",sixth_date='".date('Y-m-d')."' WHERE id=".$user_id;
			mysql_query($sql);
			
			//own point
			$sql = "UPDATE $db->matrix_sixth SET lvl_1=".$user_id.",date_1='".date('Y-m-d')."' WHERE uid=".$user_id;
			mysql_query($sql);
			$sql = "UPDATE $db->matrix_fifth SET is_qualify=1 WHERE uid=".$user_id;				
			mysql_query($sql);
			/*
			//first point
			$sql = "SELECT * FROM $db->matrix_sixth WHERE uid=".$node;
			$sponsor_matrix=@mysql_fetch_assoc(mysql_query($sql));
			if($sponsor_matrix['lvl1_1']=='0' && $np=='1'){
				$sql = "UPDATE $db->matrix_sixth SET lvl1_1=".$user_id.",date1_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_2']=='0' && $np=='2'){
				$sql = "UPDATE $db->matrix_sixth SET lvl1_2=".$user_id.",date1_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}elseif($sponsor_matrix['lvl1_3']=='0' && $np=='3'){
				$sql = "UPDATE $db->matrix_sixth SET lvl1_3=".$user_id.",date1_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
			}
			mysql_query($sql);
			
			//second point
			$sql = "SELECT * FROM $db->matrix_sixth WHERE lvl1_1=".$node;
			$q = mysql_query($sql);							
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_1']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_1=".$user_id.",date2_1='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_2']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_2=".$user_id.",date2_2='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_3']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_3=".$user_id.",date2_3='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}
			//second point
			$sql = "SELECT * FROM $db->matrix_sixth WHERE lvl1_2=".$node;
			$q = mysql_query($sql);							
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_4']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_4=".$user_id.",date2_4='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_5']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_5=".$user_id.",date2_5='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_6']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_6=".$user_id.",date2_6='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}
			//second point
			$sql = "SELECT * FROM $db->matrix_sixth WHERE lvl1_3=".$node;
			$q = mysql_query($sql);
			if(mysql_num_rows($q)>0){
				$sponsor_matrix=@mysql_fetch_assoc($q);
				if($sponsor_matrix['lvl2_7']=='0' && $np=='1'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_7=".$user_id.",date2_7='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_8']=='0' && $np=='2'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_8=".$user_id.",date2_8='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}elseif($sponsor_matrix['lvl2_9']=='0' && $np=='3'){
					$sql = "UPDATE $db->matrix_sixth SET lvl2_9=".$user_id.",date2_9='".date('Y-m-d')."' WHERE id=".$sponsor_matrix['id'];
				}
				mysql_query($sql);
			}*/
		}
	}
}

function purchase_share($uid=0, $total_cp, $datetime){
	global $vars;
 	$db=$vars["db"];
 	
	if($uid>0){
		$trade_cp = $total_cp/5;
		$sum_cp = 0;
		$bal = 0;
			
		for($i=1;$i<=5;$i++){			
			$total_sales = @mysql_result(mysql_query("SELECT sum(total_unit*buy_price) as total_sales FROM $db->share WHERE replica=0"), 0);
			if(empty($total_sales)) $total_sales = 0.1;
						
			if($i==5)
				$trade_cp = $total_cp - $sum_cp;
			
			
			switch($total_sales){
				case ($total_sales < 100000):
					$unit_price = 1;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
								
					if($total_sales+$trade_cp>100000){
						$balance_cp = 100000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.05;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 200000):
					$unit_price = 1.05;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>200000){
						$balance_cp = 200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 300000):
					$unit_price = 1.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>300000){
						$balance_cp = 300000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.15;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 400000):
					$unit_price = 1.15;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>400000){
						$balance_cp = 400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 500000):
					$unit_price = 1.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>500000){
						$balance_cp = 500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.25;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 600000):
					$unit_price = 1.25;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>600000){
						$balance_cp = 600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 700000):
					$unit_price = 1.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>700000){
						$balance_cp = 700000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.35;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 800000):
					$unit_price = 1.35;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>800000){
						$balance_cp = 800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);		
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 900000):
					$unit_price = 1.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>900000){
						$balance_cp = 900000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.45;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 1000000):
					$unit_price = 1.45;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>1000000){
						$balance_cp = 1000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 1200000):
					$unit_price = 1.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>1200000){
						$balance_cp = 1200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.55;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				
				case ($total_sales < 1400000):
					$unit_price = 1.55;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>1400000){
						$balance_cp = 1400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);			
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 1600000):
					$unit_price = 1.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>1600000){
						$balance_cp = 1600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.65;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 1800000):
					$unit_price = 1.65;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>1800000){
						$balance_cp = 1800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 2000000):
					$unit_price = 1.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>2000000){
						$balance_cp = 2000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.75;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 2200000):
					$unit_price = 1.75;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>2200000){
						$balance_cp = 2200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 2400000):
					$unit_price = 1.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>2400000){
						$balance_cp = 2400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.85;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 2600000):
					$unit_price = 1.85;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>2600000){
						$balance_cp = 2600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 2800000):
					$unit_price = 1.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>2800000){
						$balance_cp = 2800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 1.95;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 3000000):
					$unit_price = 1.95;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>3000000){
						$balance_cp = 3000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 3300000):
					$unit_price = 2.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>3300000){
						$balance_cp = 3300000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 3600000):
					$unit_price = 2.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>3600000){
						$balance_cp = 3600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 3900000):
					$unit_price = 2.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>3900000){
						$balance_cp = 3900000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 4200000):
					$unit_price = 2.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>4200000){
						$balance_cp = 4200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 4500000):
					$unit_price = 2.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>4500000){
						$balance_cp = 4500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 4800000):
					$unit_price = 2.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>4800000){
						$balance_cp = 4800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 5100000):
					$unit_price = 2.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>5100000){
						$balance_cp = 5100000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 5400000):
					$unit_price = 2.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>5400000){
						$balance_cp = 5400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 5700000):
					$unit_price = 2.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>5700000){
						$balance_cp = 5700000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 2.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 6000000):
					$unit_price = 2.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>6000000){
						$balance_cp = 6000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 6400000):
					$unit_price = 3.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>6400000){
						$balance_cp = 6400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 6800000):
					$unit_price = 3.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>6800000){
						$balance_cp = 6800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 7200000):
					$unit_price = 3.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>7200000){
						$balance_cp = 7200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 7600000):
					$unit_price = 3.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>7600000){
						$balance_cp = 7600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 8000000):
					$unit_price = 3.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>8000000){
						$balance_cp = 8000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 8400000):
					$unit_price = 3.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>8400000){
						$balance_cp = 8400000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 8800000):
					$unit_price = 3.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>8800000){
						$balance_cp = 8800000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 9200000):
					$unit_price = 3.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>9200000){
						$balance_cp = 9200000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 9600000):
					$unit_price = 3.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>9600000){
						$balance_cp = 9600000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 3.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 10000000):
					$unit_price = 3.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>10000000){
						$balance_cp = 10000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 10500000):
					$unit_price = 4.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>10500000){
						$balance_cp = 10500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 11000000):
					$unit_price = 4.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>11000000){
						$balance_cp = 11000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 11500000):
					$unit_price = 4.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>11500000){
						$balance_cp = 11500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 12000000):
					$unit_price = 4.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>12000000){
						$balance_cp = 12000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 12500000):
					$unit_price = 4.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>12500000){
						$balance_cp = 12500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 13000000):
					$unit_price = 4.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>13000000){
						$balance_cp = 13000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 13500000):
					$unit_price = 4.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>13500000){
						$balance_cp = 13500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 14000000):
					$unit_price = 4.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>14000000){
						$balance_cp = 14000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 14500000):
					$unit_price = 4.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>14500000){
						$balance_cp = 14500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 4.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;								
				case ($total_sales < 15000000):
					$unit_price = 4.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>15000000){
						$balance_cp = 15000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 15500000):
					$unit_price = 5.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>15500000){
						$balance_cp = 15500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 16000000):
					$unit_price = 5.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>16000000){
						$balance_cp = 16000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 16500000):
					$unit_price = 5.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>16500000){
						$balance_cp = 16500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 17000000):
					$unit_price = 5.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>17000000){
						$balance_cp = 17000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 17500000):
					$unit_price = 5.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>17500000){
						$balance_cp = 17500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 18000000):
					$unit_price = 5.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>18000000){
						$balance_cp = 18000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 18500000):
					$unit_price = 5.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>18500000){
						$balance_cp = 18500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 19000000):
					$unit_price = 5.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>19000000){
						$balance_cp = 19000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 19500000):
					$unit_price = 5.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>19500000){
						$balance_cp = 19500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 5.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;				
				case ($total_sales < 20000000):
					$unit_price = 5.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>20000000){
						$balance_cp = 20000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 20500000):
					$unit_price = 6.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>20500000){
						$balance_cp = 20500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 21000000):
					$unit_price = 6.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>21000000){
						$balance_cp = 21000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 21500000):
					$unit_price = 6.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>21500000){
						$balance_cp = 21500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);		
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 22000000):
					$unit_price = 6.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>22000000){
						$balance_cp = 22000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 22500000):
					$unit_price = 6.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>22500000){
						$balance_cp = 22500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 23000000):
					$unit_price = 6.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>23000000){
						$balance_cp = 23000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 23500000):
					$unit_price = 6.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>23500000){
						$balance_cp = 23500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 24000000):
					$unit_price = 6.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>24000000){
						$balance_cp = 24000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 24500000):
					$unit_price = 6.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>24500000){
						$balance_cp = 24500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 6.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;				
				case ($total_sales < 25000000):
					$unit_price = 6.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>25000000){
						$balance_cp = 25000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 25500000):
					$unit_price = 7.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>25500000){
						$balance_cp = 25500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 26000000):
					$unit_price = 7.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>26000000){
						$balance_cp = 26000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 26500000):
					$unit_price = 7.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>26500000){
						$balance_cp = 26500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 27000000):
					$unit_price = 7.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>27000000){
						$balance_cp = 27000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 27500000):
					$unit_price = 7.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>27500000){
						$balance_cp = 27500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 28000000):
					$unit_price = 7.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>28000000){
						$balance_cp = 28000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 28500000):
					$unit_price = 7.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>28500000){
						$balance_cp = 28500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 29000000):
					$unit_price = 7.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>29000000){
						$balance_cp = 29000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 29500000):
					$unit_price = 7.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>29500000){
						$balance_cp = 29500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 7.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;				
				case ($total_sales < 30000000):
					$unit_price = 7.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>30000000){
						$balance_cp = 30000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;					
				case ($total_sales < 30500000):
					$unit_price = 8.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>30500000){
						$balance_cp = 30500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 31000000):
					$unit_price = 8.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>31000000){
						$balance_cp = 31000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 31500000):
					$unit_price = 8.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>31500000){
						$balance_cp = 31500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 32000000):
					$unit_price = 8.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>32000000){
						$balance_cp = 32000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 32500000):
					$unit_price = 8.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>32500000){
						$balance_cp = 32500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 33000000):
					$unit_price = 8.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>33000000){
						$balance_cp = 33000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);	
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 33500000):
					$unit_price = 8.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>33500000){
						$balance_cp = 33500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 34000000):
					$unit_price = 8.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>34000000){
						$balance_cp = 34000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 34500000):
					$unit_price = 8.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>34500000){
						$balance_cp = 34500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;				
				case ($total_sales < 35000000):
					$unit_price = 8.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>35000000){
						$balance_cp = 35000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 8.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 35500000):
					$unit_price = 9.00;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>35500000){
						$balance_cp = 35500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.10;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 36000000):
					$unit_price = 9.10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>36000000){
						$balance_cp = 36000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.20;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 36500000):
					$unit_price = 9.20;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>36500000){
						$balance_cp = 36500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.30;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 37000000):
					$unit_price = 9.30;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>37000000){
						$balance_cp = 37000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);				
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.40;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 37500000):
					$unit_price = 9.40;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>37500000){
						$balance_cp = 37500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.50;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 38000000):
					$unit_price = 9.50;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>38000000){
						$balance_cp = 38000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.60;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 38500000):
					$unit_price = 9.60;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>38500000){
						$balance_cp = 38500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.70;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 39000000):
					$unit_price = 9.70;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>39000000){
						$balance_cp = 39000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.80;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 39500000):
					$unit_price = 9.80;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>39500000){
						$balance_cp = 39500000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 9.90;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;				
				case ($total_sales < 40000000):
					$unit_price = 9.90;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>40000000){
						$balance_cp = 40000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 10.00;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				//not yet split
				case ($total_sales < 45000000):
					$unit_price = 10;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>45000000){
						$balance_cp = 45000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 11;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				case ($total_sales < 50000000):
					$unit_price = 11;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					if($total_sales+$trade_cp>50000000){
						$balance_cp = 50000000 - $total_sales;		
						$total_unit_share = floor($balance_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
						
						$total_trade_cp = $total_unit_share*$unit_price;
						$balance_trade_cp = $trade_cp - $total_trade_cp;
						
						$unit_price = 12;
						$total_unit_share = floor($balance_trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}else{
						$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
						$sum_cp += $total_unit_share*$unit_price;
					}
					break;
				default:
					$unit_price = 12;							
					$trade_date  = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+($i*30), date("Y")));
					
					$total_unit_share = floor($trade_cp/$unit_price);
						$bal+=$total_unit_share;	
						mysql_query("INSERT INTO $db->share (uid, total_unit, buy_price, buy_date, trade_date) VALUES ('$uid','$total_unit_share','$unit_price','$datetime','$trade_date')");
						mysql_query("INSERT INTO $db->member_swallet_record (uid, type, amount, bal, cdate) VALUES ('$uid','credit','$total_unit_share','$bal','$datetime')");
						mysql_query("UPDATE $db->users SET swallet=swallet+".$total_unit_share." WHERE id=".$uid);
					$sum_cp += $total_unit_share*$unit_price;
					break;
			}
		}
	}
}function auto_repurchase($uid=0, $amount=0){			$match_qty=0;			$datetime=date('Y-m-d H:i:s');			$target=mysql_fetch_assoc(mysql_query("select * from gg_share_trading where type='sell' and qty>match_qty order by price, cdate"));			$mwallet = @mysql_result(mysql_query("select mwallet from gg_users where id=".$uid), 0) or 0;						while($amount>0){				$qty = floor($amount/$target['price']);				if($qty<=0) break;								if($qty>($target['qty']-$target['match_qty'])){					$deduct_qty = $target['qty']-$target['match_qty'];				}else{					$deduct_qty = $qty;				}				$deduct_amount = $deduct_qty * $target['price'];				$amount-=$deduct_amount;				$mwallet-=$deduct_amount;				$match_qty+=$deduct_qty;				/*				$mwallet_balance = @mysql_result(mysql_query("select mwallet from gg_users where id=".$uid), 0) or 0;				$mwallet_balance -= $deduct_amount;				mysql_query("UPDATE gg_share_target SET buy_balance=buy_balance+".$deduct_qty." WHERE share_price=".$target['price']);				mysql_query("INSERT INTO gg_member_mwallet_record (uid,type,amount,bal,descr,cdate) VALUES (".$uid.",'debit',".$deduct_amount.",".$mwallet_balance.",'Buy ".$deduct_qty." machine with price ".$target['price']."','".$datetime."')");				mysql_query("INSERT INTO gg_share_trading (uid,price,qty,match_qty,type,cdate) VALUES (".$uid.",".$target['price'].",".$deduct_qty.",".$deduct_qty.",'buy'".",'".$datetime."')");				mysql_query("UPDATE gg_share_trading SET match_qty=match_qty+".$deduct_qty." WHERE id=".$target['id']);				mysql_query("INSERT INTO gg_share_trading_ledger (trading_id, uid, buy_uid, sell_uid, price, qty, type, cdate) VALUES ('".$target['id']."', '".$target['uid']."', '".$uid."', '".$target['uid']."', '".$target['price']."', '".$deduct_qty."', 'sell', '".$datetime."')");				mysql_query("INSERT INTO gg_share_trading_ledger (trading_id, uid, buy_uid, sell_uid, price, qty, type, cdate) VALUES ('".$target['id']."', '".$uid."', '".$uid."', '".$target['uid']."', '".$target['price']."', '".$deduct_qty."', 'buy', '".$datetime."')");				*/				mysql_query("UPDATE gg_share_target SET buy_balance=buy_balance+".$deduct_qty." WHERE share_price=".$target['price']);				mysql_query("INSERT INTO gg_member_mwallet_record (uid,type,amount,bal,descr,cdate) VALUES (".$uid.",'debit',".$deduct_amount.",".$mwallet.",'Buy ".$deduct_qty." machine with price ".$target['price']."','".$datetime."')");				mysql_query("INSERT INTO gg_share_trading (uid,price,qty,match_qty,type,cdate) VALUES (".$uid.",".$target['price'].",".$deduct_qty.",".$deduct_qty.",'buy'".",'".$datetime."')");				mysql_query("UPDATE gg_share_trading SET match_qty=match_qty+".$deduct_qty." WHERE id=".$target['id']);				mysql_query("INSERT INTO gg_share_trading_ledger (trading_id, uid, buy_uid, sell_uid, price, qty, type, cdate) VALUES ('".$target['id']."', '".$target['uid']."', '".$uid."', '".$target['uid']."', '".$target['price']."', '".$deduct_qty."', 'sell', '".$datetime."')");				mysql_query("INSERT INTO gg_share_trading_ledger (trading_id, uid, buy_uid, sell_uid, price, qty, type, cdate) VALUES ('".$target['id']."', '".$uid."', '".$uid."', '".$target['uid']."', '".$target['price']."', '".$deduct_qty."', 'buy', '".$datetime."')");								$swallet_bal = @mysql_result(mysql_query("select swallet from gg_users where id='".$uid."'"), 0) or 0;				$swallet_bal += $deduct_qty;				mysql_query("INSERT INTO gg_member_swallet_record (uid, type, amount, bal, descr, cdate) values ('".$uid."','credit',".$deduct_qty.",".$swallet_bal.",'Buy machine. ".$deduct_qty." with price ".$target['price']."','".$datetime."')");				mysql_query("UPDATE gg_users SET swallet=".$swallet_bal.",mwallet=".$mwallet." WHERE id=".$uid);								$sell_ewallet_balance = @mysql_result(mysql_query("select ewallet from gg_users where id=".$target['uid']), 0) or 0;				$sell_mwallet_balance = @mysql_result(mysql_query("select mwallet from gg_users where id=".$target['uid']), 0) or 0;				$sell_ewallet_balance += $deduct_amount;				mysql_query("insert into gg_member_ewallet_record (uid,type,amount,bal,descr,cdate) values (".$target['uid'].",'credit',".$deduct_amount.",".$sell_ewallet_balance.",'Sell machinese. ".$deduct_qty." X ".$target['price']." = ".$deduct_amount."','".$datetime."')");								$sell_fee = $deduct_amount*0.1;				$sell_ewallet_balance -= $sell_fee;				mysql_query("insert into gg_member_ewallet_record (uid,type,amount,bal,descr,cdate) values (".$target['uid'].",'debit',".$sell_fee.",".$sell_ewallet_balance.",'Sell machinese. ".$deduct_amount." X 10% = ".$sell_fee."','".$datetime."')");								$com_ewallet_balance = @mysql_result(mysql_query("select ewallet from gg_users where id=9998"), 0) or 0;				$com_ewallet_balance += $sell_fee;				mysql_query("insert into gg_member_ewallet_record (uid,type,amount,bal,descr,cdate) values (9998,'credit',".$sell_fee.",".$com_ewallet_balance.",'".$target['uid']." sell machinese. ".$deduct_amount." X 10% = ".$sell_fee."','".$datetime."')");				mysql_query("update gg_users set ewallet=".$com_ewallet_balance." where id=9998");														$repurchase=0;				if($target['uid']<>9999){										$repurchase = ($deduct_amount-$sell_fee)*0.3;					$sell_ewallet_balance -= $repurchase;					$sell_mwallet_balance += $repurchase;					mysql_query("insert into gg_member_ewallet_record (uid,type,amount,bal,descr,cdate) values (".$target['uid'].",'debit',".$repurchase.",".$sell_ewallet_balance.",'30% convert to MP account.','".$datetime."')");					mysql_query("insert into gg_member_mwallet_record (uid,type,amount,bal,descr,cdate) values (".$target['uid'].",'credit',".$repurchase.",".$sell_mwallet_balance.",'30% convert from e-wallet account.','".$datetime."')");				}				mysql_query("update gg_users set ewallet=".$sell_ewallet_balance.",mwallet=".$sell_mwallet_balance." where id=".$target['uid']);								if($repurchase>0){					auto_repurchase($target['uid'], $repurchase);				}								if($amount>0){					$target=mysql_fetch_assoc(mysql_query("select * from gg_share_trading where type='sell' and qty>match_qty order by price, cdate"));					if($target['price']<=0) break;				}									}}
?>